home *** CD-ROM | disk | FTP | other *** search
- /****** axuucp/at ************************************************************
- *
- * NAME
- * @ - Append procedures to a script
- *
- * SYNOPSIS
- * rx @.rexx [scriptfile]
- *
- * DESCRIPTION
- * This script appends some of the procedures in this script to the given
- * scriptfile. The given sriptfile should contain exactly one line of
- * the form
- *
- * /*@<proc1><proc2>...<procN>*/
- *
- * The part above this line will be copied to the new scriptfile,
- * everything below will be ignored.
- * The procedures proc1, proc2, ..., procN will then be looked up in this
- * script (@.rexx) and will get appended after the /*@...*/ line in the
- * new scriptfile.
- *
- * AUTHOR
- * Tobias Ferber <tf@ganymed.hall.sub.org>
- *
- ******************************************************************************
- *
- */
-
- fname = arg(1)
- whoami = "@.rexx"
- tempfile = "T:@." || pragma('Id')
- done = 0
-
- if words(fname) < 1 then do
- say "usage: rx @.rexx [scriptfile]"
- say d2c(10) || 'Available procedures in "'whoami'":'
- call open('fp',whoami,'Read'); do until eof('fp')
- str= readln('fp'); if left(str,4)='/*@<' then do
- parse var str '/*@' str '*/'; say ' 'str; end
- end
- call close('fp')
- exit
- end
-
- /**/
-
- if open('in',fname,'Read') then do
- if open('out',tempfile,'Write') then do
-
- say 'processing "'fname'"'
-
- do until eof('in') || (done=1)
- str = readln('in')
- call writeln('out',str)
-
- if left(str,3) = '/*@' then do
- parse var str '/*@' str '*/'
- do while (words(str) > 0)
- str = strip(str)
- parse var str '<' proc '>' str
- say ' <'proc'>'
-
- if open('fp',whoami,'Read') then do
- do until eof('fp')
- l = readln('fp')
- if l = '/*@<' || proc || '>*/' then pout=1
- else do
- if left(l,3)='/*@' then pout=0
- else if pout=1 then call writeln('out',l)
- end
- end
- call close('fp')
- end
- else do
- say 'Could not read "'whoami'"'
- end
-
- end
- done=1
- end
- end
-
- call close('out')
- end
-
- else do
- say 'Could not write "'tempfile'"'
- end
-
- call close('in')
- end
-
- else do
- say 'Could not read "'fname'"'
- end
-
-
- if done=1 then do
- if exists(fname'_') then address command 'Delete QUIET FILE "'fname'_"'
- address command 'Rename QUIET FROM "'fname'" TO "'fname'_"'
- address command 'Copy QUIET FROM "'tempfile'" TO "'fname'"'
- end
-
- if exists(tempfile) then address command 'Delete QUIET FILE "'tempfile'"'
- exit
-
-
- /**/
-
-
- /*@<genseq>*/
-
- /* from `mbox2ums.rexx' by Tobias Walter */
-
- genseq: procedure
- parse arg seqfile
-
- call open('seq',seqfile,'Read')
- seq= readln('seq')
- call close('seq')
-
- if seq>1679616 then seq=1 /* 1679616 = 36*36*36*36 */
-
- call open('seq',seqfile,'Write')
- call writeln('seq',seq+1)
- call close('seq')
-
- uuseq= ""
- do i=0 to 3
- c= seq//36; seq= seq%36 /* 36 = [0-9]+[a-z] */
- if c>=10 then c= d2c(c+87) /* 87 = c2d('a')-10 */
- uuseq= c || uuseq
- end
-
- return uuseq
-
- /*@<axconfig>*/
-
- /* get an AXsh configuration value */
-
- axconfig: procedure
- tempfile = "T:axconfig." || pragma('Id')
- rc_index = "AXsh:rexx/rc.index"
- var_val=""; var_file=""; var_defval="";
-
- parse upper arg var_name
- if left(var_name,1) ~= '%' then var_name = '%'var_name
- if right(var_name,1) ~= ':' then var_name = var_name':'
-
- if open('idx',rc_index,'Read') then do
- do until (eof('idx') | (var_file~=''))
- str= translate(readln('idx'),' ',d2c(9))
- if words(str) > 0 then do
- parse var str vname ' ' fname '"' defval '"'
- if upper(vname) = var_name then do
- var_file= strip(fname,'B',' 'd2c(9))
- var_defval= defval
- end
- end
- end
- call close('idx')
- end
- else say 'Could not read "'rc_index'"'
-
- if words(var_file) > 0 then do
- if open('rc',var_file,'Read') then do
- do until (eof('rc') | (var_val~=''))
- str= translate(readln('rc'),' ',d2c(9))
- if upper(word(str,1)) = var_name then var_val = strip(readln('rc'),'B',' 'd2c(9))
- end
- call close('rc')
- end
- else say 'Could not examine "'var_file'" for' var_name
- end
- else do
- if words(var_defval) > 0 then var_val= var_defval
- else say 'No such config variable:' var_name
- end
-
- return var_val
-
- /*@<rfcaddr>*/
-
- /* expects an unfolded RFC 822 header line body, returns the address string or "" */
-
- RFCaddr: procedure expose aka
- parse arg str
- str= translate(str,' ',d2c(9))
- if pos('<',str) > 0 then do
- parse var str . "<" str ">"
- if pos(':',str) > 0 then parse var str . ':' str
- end
- else str= word(str,1)
- if pos('@',str) < 1 then str= str'@'aka
- return str
-
-
- /*@<strfmt>*/
-
- /* substitute all occurences of 'fmt' in 'str' by 'val' */
-
- strfmt: procedure
- parse arg str,fmt,val
- p= pos(fmt,str)
- do while p>0
- str= left(str,p-1) || val || substr(str,p+length(fmt))
- p= pos(fmt,str)
- end
- return str
-
-
- /*@<transquote>*/
-
- /* translate '"' into '*"' and '*' into '**' */
-
- transquote: procedure
- parse arg s
- t= s
- q= max( lastpos('*',s), lastpos('"',s) )
- do while q > 0
- t= insert('*',t,q-1,1)
- s= left(s,q-1)
- q= max( lastpos('*',s), lastpos('"',s) )
- end
- return '"' || t || '"'
-
-
- /*@<pathonly>*/
-
- /* return the non-file part of a pathname */
-
- pathonly: procedure
- parse arg path
- if (words(path) > 0) & (right(path,1) ~= ':') then do
- if right(path,1) = '/' then path= left(path,length(path)-1)
- if lastpos('/',path) > lastpos(':',path) then path= left(path,lastpos('/',path)-1)
- else path= left(path,lastpos(':',path))
- end
- return path
-
-
- /*@<fileonly>*/
-
- /* return the file part of a pathname */
-
- fileonly: procedure
- parse arg path
- if right(path,1) = '/' then path= left(path,length(path)-1)
- p= max( lastpos(':',path), lastpos('/',path) )
- if(p>0) then return substr(path,p+1)
- else return path
-
-
- /*@<tackon>*/
-
- /* concatenate the filename to the pathname and return the resulting string */
-
- tackon: procedure
- parse arg path,file
- do while left(file,1) = '/'
- file= substr(file,2)
- path= pathonly(path)
- end
- if (words(path) > 0) & (right(path,1) ~= '/') & (right(path,1) ~= ':') then path= path || '/'
- if (right(file,1) = '/') then file= left(file,length(file)-1)
- return path || file
-
-
- /*@<makepath>*/
-
- /* create all non-existant directories in a path */
-
- makepath: procedure
- parse arg path
- if right(path,1) = '/' then path= left(path,length(path)-1)
- if ~exists(path) then do
- call makepath( pathonly(path) )
- address command 'MakeDir NAME "'path'"'
- end
- return 0
-
- /*@<canexist>*/
-
- /*
- * return 1 if the device or volume name in given pathname exists
- * or if no device or volume was present (current device)
- * 0 if the device or volume name does not exist
- */
-
- canexist: procedure
- parse upper arg path
- if pos(':',path) < 1 then return 1 /* current device */
- call pragma('W','N')
- return exists( left(path,lastpos(':',path)) )
-
-
- /*@<eof>*/
-
- /*EOF*/
-